import { Link } from "umi"
import { useLocation } from "react-router"
import { Layout, Menu } from "antd"
import {
  UserOutlined,
  LaptopOutlined,
  NotificationOutlined,
} from "@ant-design/icons"

import { findParentPaths } from "@/utils/index"
import "./SiderLeft.less"


const { Sider } = Layout

interface IProps {
  loadingText?: string
}

export default function SiderLeft(props: any) {

  // console.log('获取当前路由：',useLocation());
  const { pathname } = useLocation()
  let defaultOpenKeys: any = []

  let arr = props.data.routes
  arr = arr.find((i: any) => {
    return i.path === "/"
  })
  let routesList = arr.routes
  /** *******查询需要点亮的菜单父级 根据路径获取子路由的所有父级菜单组 ********/
  defaultOpenKeys = findParentPaths(pathname)
  // console.log('最终路由：', routesList);

  return (
    <div className="systemSiderLeft">
      <div className="systemSetting">院内设置</div>
      <Sider width={200} className="systemSiderLeft-Sider">
        <Menu
          mode="inline"
          defaultSelectedKeys={[pathname]}
          defaultOpenKeys={defaultOpenKeys}
          selectedKeys={[pathname]}
          style={{ height: "100%", borderRight: 0 }}
        >
          <Menu.Item key="/system/departmentManagement" >
            <Link to="/system/departmentManagement">科室管理</Link>
          </Menu.Item>
          {/* <Menu.Item key="/system/hospitalManagement" >
            <Link to="/system/hospitalManagement">医院管理</Link>
          </Menu.Item> */}
          <Menu.Item
            key="/system/characterManagement"
          >
            <Link to="/system/characterManagement">角色管理</Link>
          </Menu.Item>
          <Menu.Item key="/system/userManagement" >
            <Link to="/system/userManagement">用户管理</Link>
          </Menu.Item>
        </Menu>
      </Sider>
    </div>
  )
}


SiderLeft.defaultProps = {
  loadingText: "加载中"
}